package com.hanzidong.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hanzidong.bean.Article;
import com.hanzidong.bean.Collect;
import com.hanzidong.bean.Comments;
import com.hanzidong.bean.Link;
import com.hanzidong.bean.User;
import com.hanzidong.dao.ArticleMapper;
import com.hanzidong.service.ArticleService;
@Service
public class ArticleServiceImpl implements ArticleService {

	@Autowired
	private ArticleMapper articleMapper;

	@Override
	public boolean add(Article article) {
		return articleMapper.add(article);
	}

	@Override
	public PageInfo<Article> listByUser(Integer pageNum, Integer pageSize, User user) {
		//分页参数
		PageHelper.startPage(pageNum, pageSize);
		
		//查询数据
		List<Article> list = articleMapper.listByUser(user);
		
		return new PageInfo<Article>(list);
	}

	@Override
	public Article getDetailById(Integer id) {
		return articleMapper.getDetailById(id);
	}

	@Override
	public PageInfo<Article> list(Integer pageNum, Integer pageSize, Article article) {
		//分页参数
		PageHelper.startPage(pageNum, pageSize);
		
		//查询数据
		List<Article> list = articleMapper.list(article);
		
		return new PageInfo<Article>(list);
	}

	@Override
	public boolean update(Article article) {
		return articleMapper.update(article);
	}

	@Override
	public PageInfo<Article> listByHits(Integer pageNum, Integer pageSize, Article article) {
		//分页参数
		PageHelper.startPage(pageNum, pageSize);
		
		//查询数据
		List<Article> list = articleMapper.listByHits(article);
		
		return new PageInfo<Article>(list);
	}

	@Override
	public PageInfo<Comments> getCommentsByArticleId(Integer id, Integer pageNum, Integer pageSize) {
		
		PageHelper.startPage(pageNum, pageSize);
		
		List list = articleMapper.getCommentsByArticleId(id);
		
		return new PageInfo<Comments>(list);
	}
	
	@Override
	public boolean addComments(Comments comments) {
		return articleMapper.addComments(comments);
	}

	@Override
	public boolean addCollect(Collect collect) {
		return articleMapper.addCollect(collect);
	}

	@Override
	public boolean delCollect(Collect collect) {
		return articleMapper.delCollect(collect);
	}

	@Override
	public PageInfo<Collect> getCollect(Integer pageNum, Integer pageSize, User user) {
		//设置分页参数
		PageHelper.startPage(pageNum, pageSize);
		
		//查询数据
		List<Collect> list = articleMapper.getCollect(user);
		
		return new PageInfo<Collect>(list);
	}

	@Override
	public Collect getCollectByArticleId(Collect collect) {
		return articleMapper.getCollectByArticleId(collect);
	}

	@Override
	public List<Link> getLinks() {
		return articleMapper.getLinks();
	}

}
